package com.xgx.distqcp.Render;

import com.jfinal.render.Render;
import com.xgx.distqcp.Common.ImageHelper;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import java.awt.*;
import java.io.IOException;

public class ImageRender extends Render {
    private  Image image;
    @Override
    public void render() {
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/png");
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            ImageIO.write(ImageHelper.toBufferedImage(image),"png",outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public ImageRender(Image img){
        this.image=img;

    }
}
